# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=jujutsu
pkgver=0.12.0
pkgrel=0
pkgdesc="Git-compatible distributed version control system"
url="https://github.com/martinvonz/jj"
# armhf, armv7, x86: tests fail
arch="all !armhf !armv7 !x86"
license="Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	libgit2-dev
	libssh-dev
	openssl-dev
	zstd-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/martinvonz/jj/archive/v$pkgver/jujutsu-$pkgver.tar.gz
	libgit2-1.7-expected-error.patch
	"
builddir="$srcdir/jj-$pkgver"

export LIBSSH2_SYS_USE_PKG_CONFIG=1
export ZSTD_SYS_USE_PKG_CONFIG=1

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release --bin jj

	for shell in bash fish zsh; do
		./target/release/jj util completion --$shell > jj.$shell
	done

	./target/release/jj util mangen > jj.1
}

check() {
	cargo test --frozen
}

package() {
	install -Dvm755 target/release/jj -t "$pkgdir"/usr/bin/

	install -Dvm644 jj.bash \
		"$pkgdir"/usr/share/bash-completion/completions/jj
	install -Dvm644 jj.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/jj.fish
	install -Dvm644 jj.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_jj

	install -Dvm644 jj.1 -t "$pkgdir"/usr/share/man/man1/
	install -dvm755 "$pkgdir"/usr/share/doc
	cp -av docs "$pkgdir"/usr/share/doc/$pkgname
}

sha512sums="
84723af97047b04ea1fa9883f691205bae04a2928012611ffcd0e4bb960dd56560b06d61b019cdb8a409bb5e7c6a79533449403411b687a3d3a8e0ef0511c6c7  jujutsu-0.12.0.tar.gz
ea7d35effcec09745ff73637855cf23c867f70ef63c849a4aa07bc4a0943ea0395dd2d72f4e2180bfe70e7c96aaed1f43da7b456da1a2ab3dfa7e18b1b61aee2  libgit2-1.7-expected-error.patch
"
